package com.lanlian.cayman.dialog;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;

import com.lanlian.cayman.R;
import com.lanlian.cayman.activity.KLineHengPingActivity;
import com.lanlian.cayman.activity.MainActivity;
import com.lanlian.cayman.activity.ZixuanActivity;
import com.scwang.smartrefresh.layout.util.DensityUtil;

/**
 * <pre>
 *     date   : 2018/8/22 20:09
 *     desc   : K线划线工具对话框
 *     version: 1.0
 * </pre>
 */
public class DrawLinePopup implements View.OnClickListener {

    private KLineHengPingActivity mContext;
    private LinearLayout mLlHengline;
    private LinearLayout mLlXieline;
    private LinearLayout mLlShuline;
    private LinearLayout mLlMoreline;
    private LinearLayout mLlRectline;
    private LinearLayout mLlClose;

    View contentView;
    PopupWindow window;

    public DrawLinePopup(@NonNull Context context) {
        //super(context, R.style.customDialog1);
        this.mContext =(KLineHengPingActivity) context;
        LinearLayout ll=new LinearLayout(context);
        // 用于PopupWindow的View
           contentView= LayoutInflater.from(context).inflate(R.layout.dialog_drawline, ll, false);
           DensityUtil du=new DensityUtil();
           int width= du.dip2px(50);

        com.lanlian.cayman.utils.DensityUtil du2=new com.lanlian.cayman.utils.DensityUtil(mContext);
        int heiht=du2.getScreenHeight();
        int height2=du2.dip2px(44+44+6);

            // 创建PopupWindow对象，其中：
            // 第一个参数是用于PopupWindow中的View，第二个参数是PopupWindow的宽度，
             // 第三个参数是PopupWindow的高度，第四个参数指定PopupWindow能否获得焦点
           window=new PopupWindow(contentView, width, heiht-height2, true)
           {
               @Override
               public void dismiss() {

                   //super.dismiss();
                   return;
               }
           };
             // 设置PopupWindow的背景

            // 设置PopupWindow是否能响应外部点击事件
             window.setOutsideTouchable(false);
             // 设置PopupWindow是否能响应点击事件
             window.setTouchable(true);
             // 显示PopupWindow，其中：
             // 第一个参数是PopupWindow的锚点，第二和第三个参数分别是PopupWindow相对锚点的x、y偏移
             window.setAnimationStyle(R.style.animTranslate);

            initView();
    }


    public void show(View view)
    {
        com.lanlian.cayman.utils.DensityUtil du=new com.lanlian.cayman.utils.DensityUtil(mContext);
        int width= du.getScreenWidth();
        int width2=du.dip2px(50);
        int height=du.dip2px(3);
        window.showAsDropDown(view,width-width2,-height);
    }
    public boolean isShowing()
    {
        return  window.isShowing();
    }

    private void initView() {

        mLlHengline = contentView.findViewById(R.id.ll_hengline);
        mLlXieline = contentView.findViewById(R.id.ll_xieline);
        mLlShuline = contentView.findViewById(R.id.ll_shuline);
        mLlMoreline = contentView.findViewById(R.id.ll_moreline);
        mLlRectline = contentView.findViewById(R.id.ll_rectline);
        mLlClose = contentView.findViewById(R.id.ll_close);

        mLlHengline.setOnClickListener(this);
        mLlXieline.setOnClickListener(this);
        mLlShuline.setOnClickListener(this);
        mLlShuline.setOnClickListener(this);
        mLlMoreline.setOnClickListener(this);
        mLlRectline.setOnClickListener(this);
        mLlClose.setOnClickListener(this);

    }



    @Override
    public void onClick(View v)
    {
        Intent intent=new Intent();
        int id = v.getId();
        switch (id)
        {
            case R.id.iv_close:

                break;

            case R.id.ll_xieline:
                   mContext.kline.kLineView.styleView.setStyle(mContext.kline.kLineView.styleView.STYLE_TWO_POINT);
                break;
            case R.id.iv_zhixuan:
                intent.setClass(mContext,ZixuanActivity.class);
                mContext.startActivity(intent);

                break;
            case R.id.iv_hangqing:
                mContext.startActivity(new Intent(mContext, MainActivity.class)
                        .putExtra("item", 0));
                break;
            default:
                break;

        }
    }












}
